﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SharpWeb
{
    /// <summary>
    /// 日期时间拾取器
    /// </summary>
    public class DateTimePicker:InputTag
    {
        protected override void InitComponent(ComponentContext context)
        {
            base.InitComponent(context);
            this.type = InputTagType.text;
            this.@readonly = "readonly";
            this.Attributes["class"] = "date textInput readonly";
            this.datefmt = "yyyy-MM-dd HH:mm:ss";
        }
         
        /// <summary>
        /// 日期时间格式化字符串
        /// </summary>
        public string datefmt
        {
            get { return this.Attributes["datefmt"]; }
            set { this.Attributes["datefmt"] = value; }
        }
         /// <summary>
         /// 定义最小的时间
         /// </summary>
         /// <example>
         /// 静态举例：<code>
         /// minDate="2000-01-15" maxDate="2012-12-15"
         /// minDate="2000-01"    maxDate="2012-12"
         /// minDate="2000"       maxDate="2012"
         /// </code>
         /// 动态举例：<code>
         /// minDate="{%y-10}-%M-%d" maxDate="{%y}-%M-{%d+1}"
         /// minDate="{%y-10}-%M"    maxDate="{%y+10}-%M"
         /// minDate="{%y-10}"       maxDate="{%y+10}"
         /// </code>
         /// </example>
        public string minDate
        {
            get { return this.Attributes["minDate"]; }
            set { this.Attributes["minDate"] = value; }
        }
        /// <summary>
        /// 定义最大时间<seealso cref="minDate"/>
        /// </summary>
        public string maxDate
        {
            get { return this.Attributes["maxDate"]; }
            set { this.Attributes["maxDate"] = value; }
        }
        

        protected override void OnRenderEnded(System.Text.StringBuilder sb, ComponentContext context)
        {

            base.OnRenderEnded(sb, context);
            sb.Append(@"<a class=inputDateButton href=""javascript:;"">选择</a>");
        }
    }
}